{
 "cells": [
  {
   "cell_type": "raw",
   "metadata": {
    "raw_mimetype": "text/restructuredtext"
   },
   "source": [
    ".. _nb_ctaea:"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# C-TAEA\n",
    "\n",
    "\n",
    "This algorithm is implemented based on <cite data-cite=\"ctaea\"></cite> and the authors' [implementation](https://web.archive.org/web/20200916105021/https://cola-laboratory.github.io/docs/publications). The algorithm is based on [Reference Directions](../../misc/reference_directions.ipynb) which need to be provided when initializing the algorithm object.\n",
    "\n",
    "C-TAEA follows a two archive approach to balance convergence (Convergence Archive CA) and diversity (Diversity Archive DA)."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "from pymoo.algorithms.moo.ctaea import CTAEA\n",
    "from pymoo.problems import get_problem\n",
    "from pymoo.util.ref_dirs import get_reference_directions\n",
    "from pymoo.optimize import minimize\n",
    "from pymoo.visualization.scatter import Scatter\n",
    "\n",
    "problem = get_problem(\"c1dtlz1\", None, 3, k=5)\n",
    "\n",
    "ref_dirs = get_reference_directions(\"das-dennis\", 3, n_partitions=12)\n",
    "\n",
    "# create the algorithm object\n",
    "algorithm = CTAEA(ref_dirs=ref_dirs)\n",
    "\n",
    "# execute the optimization\n",
    "res = minimize(problem,\n",
    "               algorithm,\n",
    "               ('n_gen', 600),\n",
    "               seed=1,\n",
    "               verbose=False\n",
    "               )\n",
    "\n",
    "sc = Scatter(legend=False, angle=(45, 30))\n",
    "sc.add(problem.pareto_front(ref_dirs), plot_type='surface', alpha=0.2, label=\"PF\", color=\"blue\")\n",
    "sc.add(res.F, facecolor=\"none\", edgecolor=\"red\")\n",
    "sc.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "problem = get_problem(\"carside\")\n",
    "ref_dirs = get_reference_directions(\"das-dennis\", problem.n_obj, n_points=91)\n",
    "algorithm = CTAEA(ref_dirs=ref_dirs)\n",
    "\n",
    "res = minimize(problem,\n",
    "               algorithm,\n",
    "               ('n_gen', 600),\n",
    "               seed=1\n",
    "               )\n",
    "\n",
    "Scatter().add(res.F, facecolor=\"none\", edgecolor=\"red\").show()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## API"
   ]
  },
  {
   "cell_type": "raw",
   "metadata": {
    "raw_mimetype": "text/restructuredtext"
   },
   "source": [
    ".. autoclass:: pymoo.algorithms.moo.ctaea.CTAEA\n",
    "    :noindex:"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Python implementation by [cyrilpic](https://github.com/cyrilpic) based on the [original C code](https://web.archive.org/web/20200916105021/https://cola-laboratory.github.io/docs/publications)."
   ]
  }
 ],
 "metadata": {
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
